Skip to content

CDAP-21264 : Respect custom CPU and memory multipliers for Task Workers - #16196

Open
sahusanket wants to merge 2 commits into
developfrom
CDAP-21264_Respect_taskworker_multipler
Open

CDAP-21264 : Respect custom CPU and memory multipliers for Task Workers#16196
sahusanket wants to merge 2 commits into
developfrom
CDAP-21264_Respect_taskworker_multipler

Conversation

@sahusanket

Copy link
Copy Markdown
Contributor

No description provided.

@sahusanket sahusanket self-assigned this Aug 10, 2026
@sahusanket sahusanket added the build Triggers github actions build label Aug 10, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request centralizes Kubernetes CPU and memory multiplier constants in Constants.java and updates TaskWorkerServiceLauncher, KubeTwillPreparer, and PreviewServiceMain to utilize them. Feedback suggests optimizing TaskWorkerServiceLauncher by storing configuration lookups in local variables to avoid redundant calls, replacing duplicate local constants in KubeTwillPreparer with the new centralized constants, and correcting a minor typo in the Javadoc of Constants.java.

Comment on lines +206 to +213
if (cConf.get(Constants.TaskWorker.CONTAINER_CPU_MULTIPLIER) != null) {
configMap.put(Constants.Kube.CPU_MULTIPLIER,
cConf.get(Constants.TaskWorker.CONTAINER_CPU_MULTIPLIER));
}
if (cConf.get(Constants.TaskWorker.CONTAINER_MEMORY_MULTIPLIER) != null) {
configMap.put(Constants.Kube.MEMORY_MULTIPLIER,
cConf.get(Constants.TaskWorker.CONTAINER_MEMORY_MULTIPLIER));
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To avoid redundant lookups in cConf (which can be expensive as it resolves configuration variables), store the retrieved multiplier values in local variables instead of calling cConf.get() multiple times for the same key.

Suggested change
if (cConf.get(Constants.TaskWorker.CONTAINER_CPU_MULTIPLIER) != null) {
configMap.put(Constants.Kube.CPU_MULTIPLIER,
cConf.get(Constants.TaskWorker.CONTAINER_CPU_MULTIPLIER));
}
if (cConf.get(Constants.TaskWorker.CONTAINER_MEMORY_MULTIPLIER) != null) {
configMap.put(Constants.Kube.MEMORY_MULTIPLIER,
cConf.get(Constants.TaskWorker.CONTAINER_MEMORY_MULTIPLIER));
}
String cpuMultiplier = cConf.get(Constants.TaskWorker.CONTAINER_CPU_MULTIPLIER);
if (cpuMultiplier != null) {
configMap.put(Constants.Kube.CPU_MULTIPLIER, cpuMultiplier);
}
String memoryMultiplier = cConf.get(Constants.TaskWorker.CONTAINER_MEMORY_MULTIPLIER);
if (memoryMultiplier != null) {
configMap.put(Constants.Kube.MEMORY_MULTIPLIER, memoryMultiplier);
}

Comment on lines +441 to +446
if (config.containsKey(CPU_MULTIPLIER)) {
systemCpuMultiplier = config.get(CPU_MULTIPLIER);
}
if (config.containsKey(MEMORY_MULTIPLIER)) {
systemMemoryMultiplier = config.get(MEMORY_MULTIPLIER);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instead of using the locally defined CPU_MULTIPLIER and MEMORY_MULTIPLIER constants (which duplicates the configuration keys), use the newly introduced centralized constants Constants.Kube.CPU_MULTIPLIER and Constants.Kube.MEMORY_MULTIPLIER from cdap-common to ensure consistency and maintainability.

Suggested change
if (config.containsKey(CPU_MULTIPLIER)) {
systemCpuMultiplier = config.get(CPU_MULTIPLIER);
}
if (config.containsKey(MEMORY_MULTIPLIER)) {
systemMemoryMultiplier = config.get(MEMORY_MULTIPLIER);
}
if (config.containsKey(Constants.Kube.CPU_MULTIPLIER)) {
systemCpuMultiplier = config.get(Constants.Kube.CPU_MULTIPLIER);
}
if (config.containsKey(Constants.Kube.MEMORY_MULTIPLIER)) {
systemMemoryMultiplier = config.get(Constants.Kube.MEMORY_MULTIPLIER);
}

Comment on lines 1465 to 1468
float cpuMultiplier = Float.parseFloat(systemCpuMultiplier != null ? systemCpuMultiplier :
cConf.getOrDefault(CPU_MULTIPLIER, DEFAULT_MULTIPLIER));
float memoryMultiplier = Float.parseFloat(systemMemoryMultiplier != null ? systemMemoryMultiplier :
cConf.getOrDefault(MEMORY_MULTIPLIER, DEFAULT_MULTIPLIER));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use the centralized constants Constants.Kube.CPU_MULTIPLIER and Constants.Kube.MEMORY_MULTIPLIER here as well to avoid relying on duplicate local constants.

Suggested change
float cpuMultiplier = Float.parseFloat(systemCpuMultiplier != null ? systemCpuMultiplier :
cConf.getOrDefault(CPU_MULTIPLIER, DEFAULT_MULTIPLIER));
float memoryMultiplier = Float.parseFloat(systemMemoryMultiplier != null ? systemMemoryMultiplier :
cConf.getOrDefault(MEMORY_MULTIPLIER, DEFAULT_MULTIPLIER));
float cpuMultiplier = Float.parseFloat(systemCpuMultiplier != null ? systemCpuMultiplier :
cConf.getOrDefault(Constants.Kube.CPU_MULTIPLIER, DEFAULT_MULTIPLIER));
float memoryMultiplier = Float.parseFloat(systemMemoryMultiplier != null ? systemMemoryMultiplier :
cConf.getOrDefault(Constants.Kube.MEMORY_MULTIPLIER, DEFAULT_MULTIPLIER));

Comment on lines +493 to +496
/**
* Kubernetes constants.
* These same as defined in KubeTwillPreparer
*/

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Fix the grammatical typo in the Javadoc comment and update it to reflect that these are the centralized constants used by KubeTwillPreparer.

Suggested change
/**
* Kubernetes constants.
* These same as defined in KubeTwillPreparer
*/
/**
* Kubernetes constants.
* These are used by KubeTwillPreparer.
*/

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
39.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Triggers github actions build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant